<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>添加阶段</title>
    <script type='text/javascript' src='${base}/resources/js/lib/jquery.1.11.3.min.js'></script>
    <script type='text/javascript' src='${base}/resources/js/common.js'></script>
</head>
<style>

</style>
<body>
<div>
    阶段名称：${phase.name}
</div>
<button type="button" id="add" onclick="addItem()">添加项</button>
<form id="itemForm" method="post">
    <div style="width: 450px;height: 300px;margin-top:20px">
        <input type="hidden" id="phaseId" name="phaseId" value="${phase.id}">
        <table id="phaseItemTable" border="1" cellspacing="0">
            <tr>
                <td>操作</td>
                <td>名称</td>
                <td>描述</td>
                <td>权重</td>
                <td>排序</td>
            </tr>
            <#if phaseItemList??>
                <#list phaseItemList as item>
                    <tr>
                        <td>修改</td>
                        <td>${item.name!}</td>
                        <td>${item.description!}</td>
                        <td>${item.weightValue!}</td>
                        <td>${item.orderNum!}</td>
                    </tr>
                </#list>

            </#if>
        </table>
        <div style="text-align: center;"></br>
            <input type="button" onclick="save()" value="提交">
        </div>
    </div>

</form>
</body>
<script>
    var row = '<tr>'+
                    '<td><input type="button" value="删除" onclick="removeRow(this)"></td>'+
                    '<td><input type="text" value="" name="name"></td>'+
                    '<td><input type="text" value="" name="description"></td>'+
                    '<td><input type="text" value="" name="weightValue"></td>'+
                    '<td><input type="number" value="" name="orderNum"></td>'+
                    '</tr>'
    function  addItem(){
        $("table#phaseItemTable").append(row);

    }
    function save() {
        var value = $("input[name='name']").val();
        if ($.isBlank(value)) {
            $("#error_name").text("用户名不能为空");
            return false;
        }
        $.ajax({
            url: "${base}/admin/phase/phaseItem/save",
            type: "post",
            data: $("#itemForm").serialize(),
            success: function (data) {
                if (data.success) {
                    window.location.href = "${base}/admin/phase/index";
                } else {
                    alert(data.msg);
                }
            }
        })
    }
</script>
</html>